home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / sectools / dsniff / decode_snmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-16  |  843 b   |  47 lines

  1. /*
  2.   decode_snmp.c
  3.  
  4.   Simple Network Management Protocol.
  5.   
  6.   Copyright (c) 2000 Dug Song <dugsong@monkey.org>
  7.  
  8.   $Id: decode_snmp.c,v 1.1 2000/05/16 17:31:14 dugsong Exp $
  9. */
  10.  
  11. #include <sys/types.h>
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include "asn1.h"
  15. #include "decode.h"
  16.  
  17. int
  18. decode_snmp(u_char *buf, int len)
  19. {
  20.     u_char *p = buf;
  21.     int i, vers;
  22.     
  23.     if (len < 20) return (0);
  24.     
  25.     if (asn1_type(&p) != ASN1_SEQUENCE)
  26.         return (0);
  27.     i = asn1_len(&p);        /* XXX - skip sequence length */
  28.     
  29.     if (asn1_type(&p) != ASN1_INTEGER)
  30.         return (0);
  31.     if (asn1_len(&p) != 1)        /* XXX - check version length */
  32.         return (0);
  33.     vers = *p++;
  34.     
  35.     if (asn1_type(&p) != ASN1_STRING)
  36.         return (0);
  37.     i = asn1_len(&p);
  38.     if ((p - buf) + i > len)
  39.         return (0);
  40.     p[i] = '\0';
  41.     
  42.     snprintf(Buf, sizeof(Buf), "[version %d]\n%s\n", vers + 1, p);
  43.     
  44.     return (strlen(Buf));
  45. }
  46.  
  47.